package com.tuanbiao.base.mvp;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.viewbinding.ViewBinding;

import com.tuanbiao.base.BaseActivity;
import com.tuanbiao.dialog.WaitDialog;


/**
 * @author abiao
 * @since 2022/4/2 9:28
 */
public abstract class BasePresenterActivity<P extends IPresenter, B extends ViewBinding> extends BaseActivity<B> implements IView {
    protected final String TAG = this.getClass().getSimpleName();
    protected P mPresenter;
    private WaitDialog.Builder dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mPresenter = createPresenter();
        super.onCreate(savedInstanceState);
    }

    /**
     * 创建Presenter
     */
    protected abstract P createPresenter();

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void showMessage(@NonNull String message) {
        showShort(message);
    }

    @Override
    public void showMessage(int message) {
        showShort(message);
    }

    @Override
    public void showLoading() {
        if (null == dialog)
            dialog = new WaitDialog.Builder(getActivity()).setMessage("正在加载....");
        dialog.show();
    }

    @Override
    public void hideLoading() {
        if (null != dialog && dialog.isShowing()) {
            dialog.dismiss();
        }
    }
}
